<template>
<div>
    <center>
    <table border="1">
        <tr>
            <th>序号</th>
            <th>商品名称</th>
            <th>商品价格</th>
            <th>购买数量</th>
            <th>操作</th>
        </tr>
        <tr v-for="(item,index) in tlist">
            <td>{{ index+1 }}</td>
            <td>{{ item.name }}</td>
            <td>{{ item.price }}</td>
            <td><button @click="item.count++">+</button>{{ item.count }}<button @click="item.count--" v-if="item.count>0">-</button></td>
            <td><button @click="yichu(index)">移除</button></td>
        </tr>
    </table>
    <h3>总价：${{ total }}</h3>
</center>

    
</div>
  
</template>

<script>
export default {
    data(){
        return{
            ok:true,
            tlist:[{name:'iphone 8',price:'5099',count:1},{name:'iphone xs',price:'8699',count:1},{name:'iphone xr',price:'6499',count:1}]
        }
    },
    methods: {
        yichu(index){
            this.tlist.splice(index,1)
        }
    },
    computed:{
        total(){
            var total=0;
            for(let i =0; i<this.tlist.length;i++){
                total+=this.tlist[i].price*this.tlist[i].count
            }
            return total 
        }
    }
}
</script>

<style>

</style>